﻿using System;
using System.Collections.Generic;
using Assist;
using Autodesk.Revit.DB;
using YArchitech.Revit.Electric.Common;
using YJKDragCurveJig;

namespace HYRElectric.Equipment
{
	internal class EquipBoundaryCvs
	{
		public EquipBoundaryCvs(DbFamilyObject dbObj)
		{
			this.m_dbObj = dbObj;
			for (int i = 0; i < dbObj.Parameters.Count; i++)
			{
				DbFamilyParameter dbFamilyParameter = dbObj.Parameters[i];
				if (dbFamilyParameter != null)
				{
					if (dbFamilyParameter.SharedName.CompareTo(SwitchBoxesLayout.m_strKeyX) == 0)
					{
						this.m_dX = Convert.ToDouble(dbFamilyParameter.Value);
						this.m_dX = AssistFunc.mmToFeet(this.m_dX);
					}
					else if (dbFamilyParameter.SharedName.CompareTo(SwitchBoxesLayout.m_strKeyY) == 0)
					{
						this.m_dY = Convert.ToDouble(dbFamilyParameter.Value);
						this.m_dY = AssistFunc.mmToFeet(this.m_dY);
					}
					else if (dbFamilyParameter.SharedName.CompareTo(SwitchBoxesLayout.m_strKeyZ) == 0)
					{
						this.m_dZ = Convert.ToDouble(dbFamilyParameter.Value);
						this.m_dZ = AssistFunc.mmToFeet(this.m_dZ);
					}
				}
			}
			this.CreateEquipBoundaryCvs();
		}

		public List<JigEdgeInfo> CreateEquipBoundaryCvs(Transform matTrans = null)
		{
			List<JigEdgeInfo> list = new List<JigEdgeInfo>();
			for (int i = 0; i < this.m_lstBoundaryCvs.Count; i++)
			{
				Curve curve = this.m_lstBoundaryCvs[i];
				Curve curve2;
				if (matTrans != null)
				{
					curve2 = curve.CreateTransformed(matTrans);
				}
				else
				{
					curve2 = curve.Clone();
				}
				list.Add(new JigEdgeInfo(curve2));
			}
			return list;
		}

		private void CreateEquipBoundaryCvs()
		{
			this.m_lstBoundaryCvs.Clear();
			XYZ xyz = XYZ.Zero + XYZ.BasisY * this.m_dY * 0.5;
			XYZ xyz2 = xyz - XYZ.BasisY * this.m_dY;
			XYZ xyz3 = xyz2 + XYZ.BasisX * this.m_dX;
			XYZ xyz4 = xyz3 + XYZ.BasisY * this.m_dY;
			this.m_lstBoundaryCvs.Add(Line.CreateBound(xyz, xyz2));
			this.m_lstBoundaryCvs.Add(Line.CreateBound(xyz2, xyz3));
			this.m_lstBoundaryCvs.Add(Line.CreateBound(xyz3, xyz4));
			this.m_lstBoundaryCvs.Add(Line.CreateBound(xyz4, xyz));
			this.m_lstBoundaryCvs.Add(Line.CreateBound(xyz2 - XYZ.BasisY * this.m_dOffset, xyz3 - XYZ.BasisY * this.m_dOffset));
		}

		public double EquipX
		{
			get
			{
				return this.m_dX;
			}
		}

		public double EquipY
		{
			get
			{
				return this.m_dY;
			}
		}

		public double EquipZ
		{
			get
			{
				return this.m_dZ;
			}
		}

		private double m_dX = AssistFunc.mmToFeet(1000.0);

		private double m_dY = AssistFunc.mmToFeet(600.0);

		private double m_dZ = AssistFunc.mmToFeet(2200.0);

		private double m_dOffset = AssistFunc.mmToFeet(50.0);

		private List<Curve> m_lstBoundaryCvs = new List<Curve>();

		private DbFamilyObject m_dbObj;
	}
}
